﻿using Application.AppSrevices;
using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CMController : Controller
    {
        private readonly IMapper mapper;
        private readonly ICMService cMService;

        public CMController(IMapper mapper,ICMService cMService) {
            this.mapper = mapper;
            this.cMService = cMService;
        }

        public IActionResult Index1()
        {
            return View();
        }
        public IActionResult Index2()
        {
            return View();
        }

        public async Task<IActionResult> CMSelect(int pageIndex, int pageSize)
        {
            List<CM> cMs = await cMService.CMKSelect(pageIndex, pageSize);
            return Json(cMs);
        }

        public IActionResult CMSelectCount()
        {
            int num =  cMService.CMSelectCount();
            return Json(num);
        }

        public async Task<IActionResult> CMAddAsync(CMAddDto cMAddDto)
        {
            int num = await cMService.CMAddAsync(cMAddDto);
            return Json(num);
        }

        public async Task<IActionResult> CMAddAsync1(CMAddDto cMAddDto)
        {
            int num = await cMService.CMAddAsync(cMAddDto);
            return Json(num);
        }

        public async Task<int> CMDelete(int id)
        {
            return await cMService.CMDeleteAsync(id);
        }
        public async Task<IActionResult> CMSelectOpiton()
        {
            List<CMK> cMs = await cMService.CMSelectOpiton();
            return Json(cMs);
        }
        /// <summary>
        /// 显示级联下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet("CM/Cascaders")]
        public IActionResult Cascaders()
        {
            List<Cascader> cascaders = cMService.Cascaders();
            return Json(cascaders);
        }
    }
}
